home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Leser 15 / Amiga Plus Leser CD 15.iso / Tools / Development / yacas_alg / yacas_morphos / share / yacas / include / refcount.h < prev    next >
Encoding:
C/C++ Source or Header  |  2002-03-13  |  1.1 KB  |  50 lines

  1.  
  2. #ifndef __refcount_h__
  3. #define __refcount_h__
  4.  
  5. #include "lispassert.h"
  6. #include "yacasbase.h"
  7. /** Implementation of a reference-counted object. This object doesn't
  8.  *  implement deletion, it just does the bookkeeping. The routine that
  9.  *  calls DecreaseRefCount is responsible for actually deleting the
  10.  *  object if this function returns zero.
  11.  */
  12. class RefCountedObjectBase
  13. {
  14. public:
  15.     inline RefCountedObjectBase();
  16.     inline void IncreaseRefCount();
  17.     inline ReferenceType DecreaseRefCount();
  18.     inline ReferenceType ReferenceCount() const;
  19.  
  20. private:
  21.     ReferenceType iReferenceCount;
  22. };
  23.  
  24. class RefCountedObject : public RefCountedObjectBase, public YacasBase
  25. {
  26. };
  27.  
  28. inline RefCountedObjectBase::RefCountedObjectBase() : iReferenceCount(0) {}
  29.  
  30. inline void RefCountedObjectBase::IncreaseRefCount()
  31. {
  32.     LISPASSERT(iReferenceCount<ReferenceMax);
  33.     iReferenceCount++;
  34. }
  35.  
  36. inline ReferenceType RefCountedObjectBase::DecreaseRefCount()
  37. {
  38. //    LISPASSERT(iReferenceCount>0);
  39.     iReferenceCount--;
  40.     return iReferenceCount;
  41. }
  42.  
  43. inline ReferenceType RefCountedObjectBase::ReferenceCount() const
  44. {
  45.     return iReferenceCount;
  46. }
  47.  
  48. #endif
  49.  
  50.